<template>
  <div>
    <div class="midd">
      <el-card class="box-card">
        <div slot="header" class="clearfix">
          <b>新闻列表</b>
        </div>
        <div class="scall">
          <el-table :data="newsList" style="width: 100%" height="690">
            <el-table-column label="新闻ID" prop="news_event_id" width="100"></el-table-column>
            <el-table-column label="新闻标题" prop="news_event_title"></el-table-column>
            <el-table-column label="新闻内容" prop="news_event_content"></el-table-column>
            <el-table-column label="创建时间" prop="create_time"></el-table-column>
            <el-table-column fixed="right" label="操作" width="250">
              <template slot-scope="scope">
                <el-button
                  type="info"
                  plain
                  size="mini"
                  @click="lookNews(newsList[scope.$index].news_event_id),scope.$index"
                >查看</el-button>
              </template>
            </el-table-column>
          </el-table>
          <!-- <div v-for="item in newsList" :key="item.index" class="text item">
            <div style="display: flex;justify-content: space-between;">
              <span>{{item.news_event_title}}</span>
              <b>{{item.news_event_content}}</b>
              <span style="padding-right:50px">{{item.create_time}}</span>
            </div>
            <el-divider></el-divider>
          </div>-->
        </div>
        <el-pagination
          background
          layout="prev, pager, next"
          :total="1000"
          style="    z-index: 2;height: 50px;position: relative;background: #fff;margin-top: -19px;
"
        ></el-pagination>
      </el-card>
    </div>
    <el-dialog
      :visible.sync="centerDialogVisible"
      :before-close="closeDetail"
      width="40%"
      center
      :closeOnClickModal="false"
      title="新闻详情"
    >
      <el-form :model="tabData" label-width="100px" class="demo-ruleForm" style="width:95%">
        <el-form-item label="新闻ID" prop="news_event_id " >
          <el-input v-model="tabData.news_event_id" readonly></el-input>
        </el-form-item>
        <el-form-item label="新闻标题" prop="news_event_title">
          <el-input v-model="tabData.news_event_title" readonly></el-input>
        </el-form-item>
        <el-form-item label="新闻内容" prop="news_event_content ">
          <el-input type="textarea" v-model="tabData.news_event_content" readonly></el-input>
        </el-form-item>        
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: "",
  data() {
    return {
      tabPosition: "left",
      newsList: [], //新闻列表
      tabData: {
        news_event_id: "",
        news_event_title: "",
        news_event_content: ""
      },
      centerDialogVisible:false
    };
  },
  mounted() {
    //比赛指南列表
    this.getNews();
  },
  methods: {
    //新闻赛事列表
    getNews() {
      var that = this;
      that.$axios
        .get("apis/admin/newseventlist")
        .then(function(res) {
          if (res.status == 200) {
            if (res.data.status == 1) {
              var dataLiat = res.data.data;
              for (var i = 0; i < dataLiat.length; i++) {
                dataLiat[i].create_time = that
                  .$moment(dataLiat[i].create_time)
                  .format("YYYY-MM-DD");
              }
              that.newsList = dataLiat;
            }
          }
        })
        .catch(function(error) {
          console.log(error);
        });
    },
    //查看新闻赛事详情
    lookNews(id) {
      var that = this;
      that.$axios
        .post("apis/admin/newseventlistdetail", this.$qs.stringify({
          newsEventId:id
        }))
        .then(function(res) {
          if (res.status == 200) {
            if (res.data.status == 1) {
              that.centerDialogVisible = true; 
              that.tabData = res.data.data
              that.$message({
                message: "查询成功~",
                type: "success"
              });
            }
          }
        })
        .catch(function(error) {
          console.log(error);
        });      
    },
    closeDetail() {
      this.centerDialogVisible = false;
    }
  }
};
</script>

<style lang="less" scoped>
.midd {
  width: 1200px;
  margin: 10px auto;
  .box-card {
    width: 100% !important;
  }
  .text {
    font-size: 14px;
  }

  .item {
    margin-bottom: 18px;
  }

  .clearfix:before,
  .clearfix:after {
    display: table;
    content: "";
  }
  .clearfix:after {
    clear: both;
  }

  .box-card {
    width: 480px;
  }
  .el-pagination {
    display: flex;
    justify-content: center;
  }
  .scall {
    height: 659px;
    overflow: scroll;
  }
}
</style>